<template>
  <div>
<!--    查询条件-->
    <div>
      <br>
      <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label="申请类型">
          <el-select v-model="formInline.jr_product_type" placeholder="申请类型">
            <el-option label="请选择" value=""></el-option>
            <el-option label="租房分期" value="1"></el-option>
            <el-option label="收房贷" value="2"></el-option>
            <el-option label="应收租约保理" value="3"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="申请状态">
          <el-select v-model="formInline.apply_state" placeholder="申请状态">
            <el-option label="请选择" value=""></el-option>
            <el-option label="待审核" value="1"></el-option>
            <el-option label="初审通过(待复审)" value="2"></el-option>
            <el-option label="初审不通过" value="3"></el-option>
            <el-option label="复审通过" value="4"></el-option>
            <el-option label="复审不通过" value="5"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="查询日期">
          <el-date-picker v-model="formInline.create_time1" type="date" placeholder="选择日期"></el-date-picker>至
          <el-date-picker v-model="formInline.create_time2" type="date" placeholder="选择日期"></el-date-picker>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="getlist">查询</el-button>
        </el-form-item>
      </el-form>
    </div>
<!--    列表信息-->
    <div>
      <el-table :data="tableData" border style="width: 100%">
        <el-table-column prop="apply_order_no" label="申请合同号" width="200"></el-table-column>
        <el-table-column prop="loan_message" label="贷款信息" width="250"></el-table-column>
        <el-table-column prop="jr_product_type" label="申请类型" width="150">
          <template slot-scope="s">
            <span v-if="s.row.jr_product_type==1">租房分期</span>
            <span v-if="s.row.jr_product_type==2">收房贷</span>
            <span v-if="s.row.jr_product_type==3">应收租约保理</span>
          </template>
        </el-table-column>
        <el-table-column prop="loan_amount" label="贷款金额" width="100"></el-table-column>
        <el-table-column prop="month_limit" label="借款期限" width="80"></el-table-column>
        <el-table-column prop="create_time" label="申请日期" width="100"></el-table-column>
        <el-table-column prop="company_name" label="资金方" width="100"></el-table-column>
        <el-table-column prop="apply_state" label="申请状态" width="100">
          <template slot-scope="s">
            <span v-if="s.row.apply_state==1">待审核</span>
            <span v-if="s.row.apply_state==2">初审通过(待复审)</span>
            <span v-if="s.row.apply_state==3">初审不通过</span>
            <span v-if="s.row.apply_state==4">复审通过</span>
            <span v-if="s.row.apply_state==5">复审不通过</span>
          </template>
        </el-table-column>
        <el-table-column prop="remarks" label="驳回原因" width="100"></el-table-column>
        <el-table-column label="操作" width="100">
          <template slot-scope="scope">
            <el-button type="text" v-if="scope.row.apply_state==1" @click="shenhe(scope.row)">审核</el-button>
            <el-button type="text" v-if="scope.row.apply_state==2" @click="shenhe(scope.row)">审核</el-button>
            <el-button type="text" v-if="scope.row.apply_state==3" @click="shenhe(scope.row)">查看</el-button>
            <el-button type="text" v-if="scope.row.apply_state==4" @click="shenhe(scope.row)">查看</el-button>
            <el-button type="text" v-if="scope.row.apply_state==5" @click="shenhe(scope.row)">查看</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
<!--    分页-->
    <div class="block">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="formInline.pageNum"
        :page-sizes="[5,10,30,50]"
        :page-size="formInline.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="formInline.total">
      </el-pagination>
    </div>
<!--    审核信息-->
    <el-dialog title="审核信息" :visible.sync="dialogVisible" width="60%" :before-close="handleClose">
      <el-form ref="form" :model="form" label-width="150px">
        <h3 style="color: #ffba00">申请主体信息</h3>
        <hr>
        <el-col :span="24">
          <el-
          <el-form-item label="申请合同号:">
            <label-wrap>{{form.apply_order_no}}</label-wrap>
          </el-form-item>
          <el-form-item label="公寓名称:">
            <label-wrap>{{form.loan_message}}</label-wrap>
          </el-form-item>
        </el-col>

        <el-form-item label="申请类型:">
          <label-wrap>{{form.jr_product_type}}</label-wrap>
        </el-form-item>
        <el-form-item label="贷款金额:">
          <label-wrap>{{form.loan_amount}}</label-wrap>
        </el-form-item>
        <el-form-item label="借款期限:">
          <label-wrap>{{form.month_limit}}</label-wrap>
        </el-form-item>
        <el-form-item label="申请日期:">
          <label-wrap>{{form.create_time}}</label-wrap>
        </el-form-item>
        <el-form-item label="资金方:">
          <label-wrap>{{form.company_name}}</label-wrap>
        </el-form-item>
        <el-form-item label="申请状态:">
          <label-wrap>{{form.apply_state}}</label-wrap>
        </el-form-item>
        <hr>



        <el-form-item>
          <template slot-scope="scope">
            <el-button @click="updatestate(scope.row.id)" v-if="scope.row.apply_state==1">审核</el-button>
            <el-button @click="updatestate(scope.row.id)" v-if="scope.row.apply_state==2">审核</el-button>
            <el-button @click="dialogVisible=false" v-if="scope.row.apply_state==3">返回</el-button>
            <el-button @click="dialogVisible=false" v-if="scope.row.apply_state==4">返回</el-button>
            <el-button @click="dialogVisible=false" v-if="scope.row.apply_state==5">返回</el-button>
            <el-button @click="dialogVisible=false" v-if="scope.row.apply_state==''">0</el-button>
          </template>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import { listCheck,listshenhe,updateapply_state } from "@/api/finance/financeCheck";
export default {
  data() {
    return {
      tableData: [],
      formInline: {
        jr_product_type: '',
        apply_state: '',
        create_time1:'',
        create_time2:'',
        pageNum:1,
        pageSize:10,
        total:5,
      },
      dialogVisible:false,
      form:{
        id:'',
        loan_message:'',
        apply_order_no:'',
        jr_product_type:'',
        loan_amount:'',
        month_limit:'',
        create_time:'',
        company_name:'',
        apply_state:'',
      },

    }
  },
  methods:{
    /**
     * 融资申请查询
     */
    getlist() {
      listCheck(this.formInline).then(response=>{
        console.log(response.list);
        this.tableData=response.list;
        this.formInline.pageNum=response.pageNum;
        this.formInline.pageSize=response.pageSize;
        this.formInline.total=response.total;
      })
    },
    /**
     * 审核信息
     */
    shenhe(row){
      // console.log("审核信息id"+row.id);
      // console.log("审核信息类型"+row.jr_product_type)
      // console.log("审核信息状态"+row.apply_state);
      // console.log("审核信息出房合同id"+row.cf_contract_id);
      listshenhe(row.id).then(res=>{
        this.dialogVisible=true;
        console.log(res);
        this.form.loan_message=res.loan_message;
        this.form.apply_order_no=res.apply_order_no;
        this.form.jr_product_type=res.jr_product_type;
        this.form.loan_amount=res.loan_amount;
        this.form.month_limit=res.month_limit;
        this.form.create_time=res.create_time;
        this.form.company_name=res.company_name;
        this.form.apply_state=res.apply_state;
        this.form.id=res.id;
      })
    },
    /**
     * 修改状态
     */
    updatestate(id){
      console.log("修改状态id++++++++++++++++++"+id+"+++"+this.form.apply_state);
      updateapply_state(id,this.form.apply_state).then(res=>{
        if(res==true){
          this.$message.success("审核通过");
          this.dialogVisible=false;
          this.getlist();
        }else{
          this.$message.error("审核失败");
          this.dialogVisible=false;
          this.getlist();
        }
      })
    },
    /**
     * 分页信息
     * @param val
     */
    handleSizeChange(val) {
      this.formInline.pageSize=val;
      console.log(`每页 ${val} 条`);
      this.getlist();
    },
    handleCurrentChange(val) {
      this.formInline.pageNum=val
      console.log(`当前页: ${val}`);
      this.getlist();
    },
    handleClose(done) {
      this.$confirm('确认关闭？')
        .then(_ => {
          done();
        })
        .catch(_ => {});
    },
  },
  created() {
    this.getlist();
  }
}
</script>

<style scoped>

</style>
